<?php
/**
 * @purpose: 对“通知”类型中子类型为1(新增评论)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type1_encoder() {
	$fields = array("sender_id","article_title","article_url");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	#别太长了，因为content里最长存500
	$article_title = subStrCh(str_replace("%s", "% s", $article_title), 200, 'N');

	#用户A  评论了你的 ***，赶快看看去吧！
	return serialize(array(
			"usr" => $sender_id,
			"atl" => $article_title,
			"url" => $article_url,
			"msg" => '用户%s评论了你的“%s”，中赶快看看去吧！',
			));
}

function msg_notice_type1_decoder() {
	$fields = array("content", "fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$data = unserialize($content);
	if ($fmt == 'line') return _msg_notice_type1_line_fmt($data);
	if ($fmt == 'box' ) return _msg_notice_type1_box_fmt($data);
}

/**
 * @purpose: 单行展示该通知
 */
function _msg_notice_type1_line_fmt($data) {
	$o_user   = UCModUserInfo::getUser($data['usr']);
	$nickname = $o_user->getValue(USERINFO_NICKNAME);

	$sender = "<a href=\"/home/index/home/{$data['usr']}\" target='_blank'>{$nickname}</a>";
	return sprintf($data['msg'], $sender, $data['atl']); #输出处，不做html转义
}

/**
 * @purpose: 展示该通知详细信息
 */
function _msg_notice_type1_box_fmt($data) {
}



